#! /bin/bash

cd /users/Nickhawker/cluster-wiki/fbg-cluster-wiki

# Get latest version of wiki
hg pull -v https://wiki.fbg-cluster.googlecode.com/hg/
hg -v update

# Get the content at the top
line_number=`awk '/----/ {print NR;exit}' qstat.wiki`
head -$line_number qstat.wiki > temp1

# Piece together info
echo {{{ > tempopen
echo }}} > tempclose
tempnewline="\n"
echo "Last updated  -  `date +%A%t%T%t%z`" > temp2

echo "/users" > temp3
df -h /users | cut -c23-43 > temp4
cat tempopen temp3 temp4 tempclose > tempusers

echo "/scratch" > temp5
df -h /scratch | cut -c23-43 > temp6
cat tempopen temp5 temp6 tempclose > tempscratch

qstat -g c | grep -v multiway | grep -v master > temp7
qstat | head -300 > temp8

# Assemble new file
cat temp1 tempnewline temp2 tempusers tempscratch tempopen temp7 tempclose tempopen temp8 tempclose > qstat.wiki
rm temp*

# Push new version
hg commit -v -m "auto-update of qstat"
hg push -v https://qstatupdater:qx7yZ7Ee5gN9@wiki.fbg-cluster.googlecode.com/hg/
